﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using University.Workshop.DataAccess;
using System.Collections.ObjectModel;
namespace University.Workshop.Business
{
    public class LevelsManager
    {
        public Collection<LevelDatabase> Levels {get; private set;}

        public LevelsManager()
        {
            Levels = new Collection<LevelDatabase>();
        }

        public void SetLevels(Collection<LevelDatabase> levelsReceived)
        {
            if (levelsReceived != null)
            {
                foreach (LevelDatabase level in levelsReceived)
                {
                    Levels.Add(level);
                }
            }
            
        }

        public bool LevelUp(User user)
        {
            if (user != null)
            {
                int index = user.UserLevel - 1;
                if (user.UserLevel < 6)
                {
                    if (user.TimeWon >= Levels[index].TimeWon && user.Chips >= Levels[index].Chips)
                    {
                        user.UserLevel++;
                        return true;
                    }
                }
            }
            return false;
        }
    }
}
